<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <!-- 引入线上网址 js -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <div>
        <h2>Array</h2>
        <div>{{arr}}</div>
        <h2>object</h2>
      </div>
      <div>
        <button @click="changeArr">修改Object</button>
      </div>
      <div>{{user}}</div>
      <div>
        <button @click="changeObject">修改user</button>
      </div>
    </div>
    <script>
      let vm = new Vue({
        el: "#app",
        data: {
          arr: [1, 2, 3],
          user: { a: 2 },
        },
        // 方法:
        methods: {
          changeArr() {
            console.log(this.arr);
            // set (要修改的数组,修改的索引,修改的值)
            Vue.set(this.arr, 1, 999);
          },
          changeObject() {
            console.log(this.user);
            this.$set(this.user, "b", "张三");
          },
        },
      });
    </script>
  </body>
</html>
